/**
 * 
 */
package com.car.spdier.utils;

import java.io.Serializable;
import java.util.Iterator;

import com.car.spdier.service.dao.entity.Area;


/**
 * @author guojing.zhang
 *
 */
public class AreaUtil implements Serializable {
	 /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static java.util.Map<String, Area> hashTable = new java.util.Hashtable<String, Area>() ;
	/**
	 * @param args
	 */
	 static {
		  putArea("021", "上海","沪");
		  putArea("010", "北京","京");
		  putArea("022", "天津","津");		  		  
		  putArea("0512", "苏州","苏");
		  
	 }
	 public static Area getAreaByCode(String code){
		 if(hashTable.containsKey(code)){
			 return hashTable.get(code);
		 }
		return null;
	 }
	 private static void putArea(String code,String name,String shortName){
		 Area area= new Area(  code,  name,  shortName);
		 hashTable.put(code,area);
	 }
	 public static String getAreaNameByCode(String code){
		 if(hashTable.containsKey(code)){
			 return hashTable.get(code).getCityName();
		 }
		 return null;
	 }
 
	 public static String getAreaCodeByName(String areaName){
		 if(null!=( areaName )){
			 Iterator its=hashTable.values().iterator();
			 while(its.hasNext()){
				Object areaNameObj= its.next();
				if(areaNameObj!=null&&areaName.equals( areaNameObj.toString())) {
					return areaNameObj.toString();
				}
			 }
		 }
		 return null;
	 }
	 public static String getAreaCodeByShortName(String areaShortName){
		
		 if( null!= areaShortName ){
			 Iterator its=hashTable.values().iterator();
			 while(its.hasNext()){
				Object areaNameObj= its.next();
				if(areaNameObj!=null&&areaShortName.equals( areaNameObj.toString())) {
					return areaNameObj.toString();
				}
			 }
		 }
		 return null;
	 }
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
